package od;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Copyright (C) 2023 思创数码科技股份有限公司
 * <p/>
 * 版权所有
 * <p/>
 * 类名　　  : Test_3
 * 功能概要  :
 *
 * @author yangwk
 * @date 2025/3/4 19:58
 */
public class 信号量 {
    static boolean[][] visited;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int row = scanner.nextInt();
        int col = scanner.nextInt();
        int[][] arr = new int[row][col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }
        if(row==0||col==0){
            System.out.println(0);
        }
        visited = new boolean[row][col];
        int desRow = scanner.nextInt();
        int desCol = scanner.nextInt();
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                if (arr[i][j] > 0) {
                    List<int[]> path = new ArrayList<>();
                    path.add(new int[]{i, j});
                    dp(arr, arr[i][j],path);
                }
            }
        }

        System.out.println(arr[desRow][desCol]);
    }

    static void dp(int[][] arr, int val, List<int[]> path) {
        while (!path.isEmpty()){
            int size= path.size();
            while (size-->0) {
                int[] remove = path.remove(0);
                int sourceRow = remove[0], sourceCol = remove[1];
                if (val == 0) {
                    continue;
                }
                if (!(sourceRow >= 0 && sourceRow < arr.length && sourceCol >= 0 && sourceCol < arr[0].length)) {
                    continue;
                }
                if (arr[sourceRow][sourceCol] == -1) {
                    continue;
                }
                if (visited[sourceRow][sourceCol]) {
                    continue;
                }
                visited[sourceRow][sourceCol] = true;
                arr[sourceRow][sourceCol] = val;
                path.add(new int[]{sourceRow + 1, sourceCol});
                path.add(new int[]{sourceRow - 1, sourceCol});
                path.add(new int[]{sourceRow, sourceCol - 1});
                path.add(new int[]{sourceRow, sourceCol + 1});
            }
            val -= 1;
        }

    }


}
